Ext.apply(Ext.form.VTypes, {
    confirmPwd: function (val, field) {
        if (field.confirmPwd) {
            var firstPwdId = field.confirmPwd.first;
            var secondPwdId = field.confirmPwd.second;
            this.firstField = Ext.getCmp(firstPwdId);
            this.secondField = Ext.getCmp(secondPwdId);
            var firstPwd = this.firstField.getValue();
            var secondPwd = this.secondField.getValue();
            if (firstPwd == secondPwd) {
                return true;
            } else {
                return false;
            }
        }
    },
    confirmPwdText: '两次输入的密码不一致!'
});
Ext.define('ChangePasswordWindow', {
    extend: 'Ext.window.Window',
    title: "修改密码",
    width: 500,
    draggable: false,
    modal: true,
    initComponent: function () {
        Ext.apply(this, {
            items: [
                {
                    itemId: 'form',
                    xtype: 'form',
                    layout: 'form',
                    labelWidth: 75, // label settings here
                    // cascade unless overridden
                    border: false,
                    bodyStyle: 'padding:10px',
                    defaults: {
                        width: 230
                    },
                    defaultType: 'textfield',
                    items: [
                        {
                            fieldLabel: '旧密码',
                            name: 'oldPassword',
                            inputType: 'password',

                            allowBlank: false
                        },
                        {
                            fieldLabel: '设置新密码',
                            id: 'xgmm_new1',
                            name: 'password',
                            inputType: 'password',
                            allowBlank: false
                        },
                        {
                            fieldLabel: '确认新密码',
                            id: 'xgmm_new2',
                            name: 'password2',
                            inputType: 'password',
                            confirmPwd: {
                                first: 'xgmm_new1',
                                second: 'xgmm_new2'
                            },
                            vtype: 'confirmPwd',
                            allowBlank: false
                        }
                    ]
                }
            ],
            buttons: [
                {
                    text: '提交修改',
                    scope: this,
                    handler: function () {
                        var _this = this;
                        this.getComponent('form').getForm().submit({
                            clientValidation: true,
                            url: F.url('/admin/updatePwd.do'),
                            success: function (form, action) {
                                UI.showSuccessMsg('密码修改成功');
                                _this.close();
                            },
                            failure: ajax_form_failed
                        });
                    }
                }
            ]
        });
        this.callParent();
    }
});